package com.zenchn.utils;

import org.apache.commons.codec.digest.DigestUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * PwdHashSaltUtils：
 * 密码 哈希加盐
 * @author dingxinfa
 * @date 2020-05-22 14:00
 */
public class PwdHashSaltUtils {

    public static final String PUBLIC_SALT = "zenchn";



    /***
     * 原始值 加盐二次加密  --密码加密保存通过该接口
     * @param privateSalt  私盐
     * @param primitiveValue   原始值
     * @return
     */
    public static String primitiveSha256Hex(String privateSalt,String primitiveValue) {
        return DigestUtils.sha256Hex(privateSalt+DigestUtils.sha256Hex(primitiveValue)+PUBLIC_SALT);
    }


    /***
     * 一次SHA256加密值 再次加盐加密--登录后验证通过该接口
     * @param privateSalt  私盐
     * @param sha256HexValue   一次SHA256加密值
     * @return
     */
    public static String againSha256Hex(String privateSalt,String sha256HexValue) {
        return DigestUtils.sha256Hex(privateSalt+sha256HexValue+PUBLIC_SALT);
    }



    public static void main(String[] args) {
/*        Map<String,String> map=new HashMap<>();
        map.put("yunwei","3860714f2d7f6c95ab0f955bbb41eb7bb2aa0c65fa39c03339d5b97fdc06ba61");
        map.put("asd021","ecb772e06868c8bd45f33be55bd55e96b98283be42fc92a19f6f06f417762cb8");
        map.put("dededede","0ba752e00769722164ea55bf6c96c2bcc47fc6ecfd4a35380b48279feec3ed53");
        map.put("chhTest","4081bcf6c87d8386b70bfc6455a0b0e106267d1b291df1687e1733e68522307f");
        map.put("dededede123","ec23a1165989c9164279f22c1ff623fae8f9536acc798a54c07776fb53d9dcfc");
        map.put("testtest","ecd71870d1963316a97e3ac3408c9835ad8cf0f3c1bc703527c30265534f75ae");


        map.forEach((privateSalt,sha256HexValue)->{
            System.out.println(privateSalt+","+againSha256Hex(privateSalt,sha256HexValue));
        });*/

        System.out.println(DigestUtils.sha256Hex("000000"));
        System.out.println(againSha256Hex("system","91b4d142823f7d20c5f08df69122de43f35f057a988d9619f6d3138485c9a203"));
        System.out.println(againSha256Hex("system","96b52c9343b6f7ab2591db0177479e048cc6c3cdb4be966c91f7a37c78c21554"));
        System.out.println(primitiveSha256Hex("test0706","zdzc123"));
    }
}
